typedef struct ListNode ListNode;
//创建一个节点
ListNode* BuyNode(int x)
{
    ListNode* node = (ListNode*)malloc(sizeof(ListNode));
    node->val = x;
    node->next = NULL;
    return node;
}

//形成一个环形链表
ListNode* nodecircle(int n)
{
    ListNode* ptail = NULL;
    ListNode* phead = BuyNode(1);
    ptail = phead;
    for(int i = 2;i <= n;i++)
    {
        ptail->next = BuyNode(i);
        ptail = ptail->next;
    }
    ptail->next = phead;
    return ptail;
}

int ysf(int n, int m )
{
    ListNode* prev, *pcur;
    prev = nodecircle(n);
    pcur = prev->next;
    int count = 1;
    while(pcur->next != pcur)
    {
        if(count == m)
        {
            //销毁该节点
            prev->next = pcur->next;
            free(pcur);
            pcur = prev->next;
            count = 1;
        }
        else
        {
            //跳过继续报数
            prev = pcur;
            pcur = prev->next;
            count++;
        }
    }
    return pcur->val;
}